#include <iostream>

using namespace std;

//电灯类
class Light
{
public:
    void on()
    {
        cout << "Light on !" << endl;
    }

    void off()
    {
        cout << "Light off !" << endl;
    }
};
//命令类
class Command
{
public:
    virtual void execute(){}
};
//具体命令类
class LigthOnCommand : public Command
{
public:
    LigthOnCommand(Light* lig):light(lig){}
    //execute方法
    void execute()
    {
        light->on();
    }
private:
    Light* light;
};

class LigthOffCommand : public Command
{
public:
    LigthOffCommand(Light* lig):light(lig){}
    void execute()
    {
        light->off();
    }
private:
    Light* light;
};

//遥控器类
class RemoteControl
{
public:
    void setCommand(Command* command)
    {
        slot = command;
    }
    void buttonOn()
    {
        slot->execute();
    }
private:
    Command* slot;
};
//客户代码
int main()
{
    RemoteControl lightOnControl;
    RemoteControl lightOffControl;

    Command* onCommand = new LigthOnCommand(new Light());
    Command* offCommand = new LigthOffCommand(new Light());

    lightOnControl.setCommand(onCommand);
    lightOffControl.setCommand(offCommand);

    lightOnControl.buttonOn();
    lightOffControl.buttonOn();

    return 0;
}
